
innerapp.controller('server_log_Ctrl', function ($scope,$http) {
    $scope.carname = "日志记录";
    $http.get("/Service/logfile/getLogfiles/")
    .then(function (result) {
        $scope.logs = result.data;
        
        if($scope.logs.length > 0)
            $scope.toggle($scope.logs[0]);
            //$scope.currentFile = $scope.logs[0];
    });
    
    $scope.toggle = function(item) {
        $scope.currentFile = item;
        $http.get("/Service/logfile/getLogfileByName/?fname=" + item)
        .then(function (result) {
            var datas = result.data.split("\n");
            var logInfos = new Array();
            var index = 0;
            for ( var i = datas.length - 1; i >= 0; i--){
                var info = datas[i].trim();
                if(info.length <= 0){
                    continue;
                }
                var date = datas[i].substr(0,10)
                var time = datas[i].substr(11,8)
                var index1 = datas[i].indexOf("[",19);
                var index2 = datas[i].indexOf("]",index1);
                var infoLevel = datas[i].substr(index1,index2 - index1 + 1);
                index1 = datas[i].indexOf("[",index2);
                index2 = datas[i].indexOf("]",index1);
                var codeFile = datas[i].substr(index1,index2 - index1 + 1);
                var content = datas[i].substr(index2 + 1);
                logInfos[index] = {date:date,time:time, infoLevel:infoLevel,codeFile:codeFile,content:content};
                index ++;
            }
            $scope.logInfos = logInfos;
        });
    };
});